/**
 * 时间字符串排序: 
 */

function timeStringSort() {

  let arr = ['2020-1-11', '2020-12-11', '2020-10-11', '2020-9-11', '1996-1-11']
  arr.sort((a, b) => { return Date.parse(a.replace(/-/g, "/")) - Date.parse(b.replace(/-/g, '/')) })
  //  Date.parse(b.CreatedTime.replace(/-/g, "/")) - Date.parse(a.CreatedTime.replace(/-/g, "/"))
  console.log(arr);
  return arr

}

timeStringSort()

function timeStringSortV2() {
  
  let arr = ['2020-1-11 12:12:90', '2020-1-11 10:12:90', '2020-10-11 12:12:90', '2020-9-11 12:12:90', '1996-1-11 12:12:90']
  arr.sort((a, b) => { return Date.parse(a.split(' ')[0].replace(/-/g, "/")) - Date.parse(b.split(' ')[0].replace(/-/g, '/')) })
  console.log(arr);
  return arr
}

timeStringSortV2()

let a = '2020-12-1'
console.log(a.replace(/-/g,'/'));
console.log(Date.parse(a.replace(/-/g, "/")));

